<?php
/* Template Name: 读者墙 
 * Author: Cleris
 */
 get_header();

//导航菜单
	$custom_fields = get_post_custom_keys($post_id);
	if( !in_array( 'pgmenu', $custom_fields) ){
		$pgmenu = 1;
	}
?>
<div class="hide"><?php ini_map()?></div>
<?php while(have_posts()): the_post()?>
	<div class="main-page" <?php if( $pgmenu!==1 ) echo 'style="padding:20px 25px"'?>>
		<?php if( $pgmenu==1 && !ismobile() ) wp_nav_menu( array('theme_location' => 'pagemenu', 'class' => 'pg-menu') )?>
		<h2 class="entry-title"><?php the_title()?></h2>
		<span><?php edit_post_link('编辑文章','<i class="icon-edit"></i> ')?></span>
		<p class="excerpt hide"><?php bloginfo('name')?>的读者墙</p>
		<div class="context" property="v:description"><?php the_content(); ?></div>
		<?php ini_bdshare()?>
		<ul class="flink visitor">
<?php
$count = get('ini_gbook')? get('ini_gbook'): 24;
$query = "SELECT COUNT(comment_ID) AS cnt, comment_author, comment_author_url, comment_author_email FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE comment_date > date_sub( NOW(), INTERVAL 6 MONTH ) AND user_id='0' AND comment_author_email != '' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT $count";
$wall = $wpdb->get_results($query);
foreach ($wall as $comment){
	$avatar = get_avatar( $comment->comment_author_email, 40 );
	if( $comment->comment_author_url ){
		$url = "href=\"".$comment->comment_author_url."\" rel=\"external nofollow\"";
	}
	else { $url=""; }
	$tmp = "<a $url><img class=\"avatar\" width=\"40\" height=\"40\" src=\"".TPDIR."/res/avatar.jpg\" alt=\"avatar\" data-original=\"".preg_replace(array('/^.+(src=)(\"|\')/i', '/(\"|\')\sclass=(\"|\').+$/i'), array('', ''), $avatar )."\"/><i>".$comment->comment_author."</i>已在本站点评".$comment->cnt."次<div class=\"clear\"></div></a>";
	$output.= '			<li class="slow">'.$tmp.'</li>';
}
echo $output ?> 
			<div class="clear"></div>
		</ul>
<?php if('open'== $post->comment_status) comments_template()?>
<?php endwhile?>
	</div>
<?php get_footer()?>